package com.tdd.client;

import com.tdd.common.MessageDecoder;
import com.tdd.common.MessageEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @author xiaoxiyuan
 * @description 客户端初始化
 * @date 2020-06-11 15:19:30
 */
public class MyClientInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        //创建SocketChannel的同时创建一个ChannelPipeline
        ChannelPipeline pipeline = ch.pipeline();
        //编码器，即向ChannelPipeline中添加编码器处理器
        pipeline.addLast(new MessageEncoder());
        //解码器，即向ChannelPipeline中添加解码器处理器
        pipeline.addLast(new MessageDecoder());
        //客户端处理器，即向ChannelPipeline中添加客户端发送消息或接收消息的处理器
        pipeline.addLast(new MyClientHandler());

    }
}
